<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>培训记录</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="/worker_assets/css/bootstrap.min.css" rel="stylesheet">
	<link href="/worker_assets/css/style.css" rel="stylesheet">
	<link href="/worker_assets/css/font-awesome.css" rel="stylesheet">
</head>
<body>
	<div class="container-fluid">
		<div class="om-ctl-mes">
			<div class="title">
				<div class="col-xs-12"><span class="fa fa-list-ul"> 员工管理</span><b class="fa fa-caret-right"></b><i>培训记录</i></div>
			</div>
			<div class="seltemple">
				<div class="col-xs-12">
                    <form class="form-inline form" method="get" action="/admin_train">
                    <div class="col-xs-3 mes-group"><label>部门</label><select name="department"><option value="0">请选择</option><?foreach($tDDatas as $tDRow){?><option value="<?=$tDRow['num']?>" <?if($pDepartment == $tDRow['num']){echo 'selected';}?>><?=$tDRow['introduce']?></option><?}?></select></div>
                    <div class="col-xs-3 sel-data">
                    <label for="exampleInputName2">培训时间</label>
                    <div class="input-group date form_date" data-date="" data-date-format="yyyy-mm-dd" data-link-field="updated">
                    <input class="form-control" name="train_date" size="16" id="form-control" value="<?=$pTraindate?>" onclick="WdatePicker();" readonly="" placeholder="选择培训日期" type="text">
                    </div>
                    <input id="updated" value="" name="updated" type="hidden"><br>
                    </div>			
                    <div class="col-xs-3 mes-search"><label>关键词搜索</label><input type="text" name="keyword" value="<?=$pKeyword?>" placeholder="员工姓名/联系电话"><button type="button" id="search">搜索</button></div>
					<div class="col-xs-3 mes-btn"><button type="button" id="off-btn">新增记录</button></div>
                </form>
				</div>
			</div>
			<div  class="mes-conttent col-xs-12">
				<table class="table study-table">
	              <thead>
	             	<tr>
			        <th>编号</th>
			        <th>姓名</th>
			        <th>联系电话</th>
			        <th>所在部门</th>
			        <th>培训时间</th>
			        <!--<th>培训类型</th>
			        <th>培训机构</th>
			        <th>培训名称</th>-->
			        <th>培训内容</th>
			        <th>是否获得证书</th>
			        <th>备注</th>
			        <th>操作</th>
		            </tr>
	              </thead>
	             <tbody>
                    <?foreach($tDatas as $tRow){?>
		           <tr>
                        <td><?=$tRow['id']?></td>
                        <td><?=$tRow['name']?></td>
                        
                        <td><?=$tRow['phone']?></td>
                        <td><?=$tRow['department']?></td>
                        <td><?=$tRow['train_date']?></td>
                        <!--<td><?=$tTraintype[$tRow['train_type']]?></td>
                        <td><?=$tRow['train_company']?></td>
                        <td><?=$tRow['train_name']?></td>-->
                        <td><?=$tRow['description']?></td>
                        <td><?=$tIscertificate[$tRow['is_certificate']]?></td>
                        <td><?=$tRow['remarks']?></td>
			         <td>
                     <button data="<?=$tRow['id']?>" type="button" class="edit-btn">编辑</button>
			         	<button>删除</button>
			         </td>
		           </tr>
                    <?}?>
	            </tbody>
              </table>
                <?=$tShow?>
			</div>
		</div>
    </div>
      <script type="text/javascript" src="/worker_assets/js/jquery.min.js"></script>
    <script type="text/javascript" src="/worker_assets/js/jq.js"></script><small class="hiddendiv"></small>
<script src="/plugins/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/plugins/datepicker/WdatePicker.js" charset="UTF-8"></script>
<script>
$(function(){
	var offalert="<div class='off-alert'></div>",
	    html = "<div class='mark'></div>"
	           +"<div class='off-alert'>"
				  +"<h3>新增记录<span id='close'>×</span></h3>"
				  +"<form method='post' class='addTrain'>"
                  +"<div class='sle'><label>部门</label><select name='department' class='department'><option value='0'>请选择</option><?foreach($tDDatas as $tDRow){?><option value='<?=$tDRow["num"]?>'><?=$tDRow["introduce"]?></option><?}?></select><label class='supportworker_name'>姓名</label><select name='supportworker' class='supportworker'><option>请选择</option></select><label>培训时间</label><input type='text' onclick='WdatePicker()' name='train_date' readonly='readonly' placeholder='2017-09-12'></select></div>"
				   +"<div class='col-xs-12'><div class='col-xs-6'><label>培训类型</label><input type='radio' name='train_type' value='1'> 集中<input type='radio' name='train_type' value='2'> 自学<input type='radio' name='train_type' value='3'> 网络</div><div class='col-xs-6'><label>获得证书</label><input type='radio' name='is_certificate' value='1'> 是<input type='radio' name='is_certificate' value='2'> 否</div></div>"
				  +"<div class='col-xs-12'><div class='col-xs-4'>培训机构</div><div class='col-xs-8'><input type='text' name='train_company' value=''></div></div>"
				  +"<div class='col-xs-12'><div class='col-xs-4'>培训名称</div><div class='col-xs-8'><input type='text' name='train_name' value=''></div></div>"
				  +"<div class='col-xs-12'><div class='col-xs-4'>培训内容</div><div class='col-xs-8'><textarea name='description' value=''></textarea></div></div>"
				  +"<div class='col-xs-12'><div class='col-xs-4'>备注</div><div class='col-xs-8'><input type='text' name='remarks' value=''></div></div>"
                  +"<div class='btns'><button type='button' onclick='addUser()'>保存</button><button type='button' class='cancleBtn'>取消</button></div>"
                  +"</form>"
          +"</div>";
	   $("body").prepend($(html))
    $(".mark").css("height",$(document).height()+"px")		
   $(".mark").addClass('hidden')	
   $(".off-alert").addClass('hidden')
      $("#off-btn").click(function(){
           $('.mark').show()
           $('.off-alert').show()
           $(".off-alert").removeClass('hidden')
           $(".mark").removeClass('hidden')
            $('select[name="department"]').change(function(){
                var department_id = $(this).val();
                $.post('/admin_train',{department_id:department_id},function(obj){
                    $('select[name="supportworker"]').remove();
                    if(obj.status == 1){
                        var data = obj.data;
                        var html = (
                            '<select name="supportworker">'
                        );
                        $.each(data,function(key,row){
                            html += '<option value="'+row.id+'">'+row.name+'</option>';
                        }); 
                        html += '</select>';
                        html += '<input type="hidden" name="tId" value="" class="tId"/>'
                        $('.supportworker_name').after(html);
                    }
                });
            });
       
     })
    $("#close").click(function(){
           $('.mark').hide()
           $('.off-alert').hide()
           $(".off-alert").addClass('hidden')
           $(".mark").addClass('hidden')
     })
    $(".cancleBtn").click(function(){
           $('.mark').hide()
           $('.off-alert').hide()
           $(".off-alert").addClass('hidden')
           $(".mark").addClass('hidden')
     })
})
$(function(){
	//var offalert-edit="<div class='off-alert-edit'></div>",
	$("body").prepend("<div class='mark-edit'></div><div class='off-alert-edit'><h3>新增记录<span id='close-edit'>×</span></h3><form method='post' class='editTrain'><div class='sle'><label>部门</label><select name='department' class='department'><option value='0'>请选择</option><?foreach($tDDatas as $tDRow){?><option value='<?=$tDRow["num"]?>'><?=$tDRow["introduce"]?></option><?}?></select><label class='supportworker_name'>姓名</label><select name='supportworker' class='supportworker'><option>请选择</option></select><label>培训时间</label><input type='text' class='train_date' onclick='WdatePicker()' name='train_date' readonly='readonly' placeholder='2017-09-12'></select></div><div class='col-xs-12'><div class='col-xs-6'><label>培训类型</label><input type='radio' class='train_type' name='train_type' value='1'> 集中<input type='radio' class='train_type' name='train_type' value='2'> 自学<input type='radio' class='train_type' name='train_type' value='3'> 网络</div><div class='col-xs-6'><label>获得证书</label><input type='radio' class='is_certificate' name='is_certificate' value='1'> 是<input type='radio' class='is_certificate' name='is_certificate' value='2'> 否</div></div><div class='col-xs-12'><div class='col-xs-4'>培训机构</div><div class='col-xs-8'><input type='text' name='train_company' class='train_company' value=''></div></div><div class='col-xs-12'><div class='col-xs-4'>培训名称</div><div class='col-xs-8'><input type='text' class='train_name' name='train_name' value=''></div></div><div class='col-xs-12'><div class='col-xs-4'>培训内容</div><div class='col-xs-8'><textarea class='description' name='description' value=''></textarea></div></div><div class='col-xs-12'><div class='col-xs-4'>备注</div><div class='col-xs-8'><input type='text' name='remarks' class='remarks' value=''></div></div><div class='btns'><button type='button' class='editUser'>保存</button><button type='button' class='edit-cancleBtn'>取消</button></div></form></div>");
	   //$("body").prepend($(edit-html))
    $(".mark-edit").css("height",$(document).height()+"px")		
   $(".mark-edit").addClass('hidden')	
   $(".off-alert-edit").addClass('hidden')
   $(".edit-btn").each(function(){
      $(this).click(function(){
           $('.mark-edit').show()
           $('.off-alert-edit').show()
           $(".off-alert-edit").removeClass('hidden')
           $(".mark-edit").removeClass('hidden')
        var t_id = $(this).attr('data');
        $.get('/admin_train',{t_id:t_id},function(obj){
            if(obj.status == 1){
                var data = obj.data;
                $('select[class="department"]').val(data.department);
                //$('select[class="supportworker"]').val(data.w_id);
                sel(data);
                $('input[class="train_date"]').val(data.train_date); 
                $('input[class="train_type"]')[data.train_type-1].checked = true;
                $('input[class="train_company"]').val(data.train_company);
                $('input[class="train_name"]').val(data.train_name);
                $('input[class="is_certificate"]')[data.is_certificate-1].checked = true;
                $('textarea[class="description"]').val(data.description);
                $('textarea[class="remarks"]').val(data.remakrs);
                tId = data.id;
            }    
        });
        $('.editUser').click(function(){
            var edit_data = $('form[class="editTrain"]').serialize();
            edit_data += '&tId='+tId;
            $.post('/admin_train/edit',edit_data,function(obj){
                    if(obj.status == 0){
                        alert(obj.msg);return;
                    }
                    alert(obj.msg);
                    location.href="/admin_train";});
        });
       
     })
   
   });
    $("#close-edit").click(function(){
           $('.mark-edit').hide()
           $('.off-alert-edit').hide()
           $(".off-alert-edit").addClass('hidden')
           $(".mark-edit").addClass('hidden')
     })
    $(".edit-cancleBtn").click(function(){
           $('.mark-edit').hide()
           $('.off-alert-edit').hide()
           $(".off-alert-edit").addClass('hidden')
           $(".mark-edit").addClass('hidden')
     })

})
$('#search').click(function(){
    $('.form').submit();
});
/*获取地址栏参数*/
function GetQuery(key){
	var search = location.search.slice(1);//得到get方式提交的查询字符串
	var arr = search.split("&");
	for(var i = 0; i < arr.length; i++){
		var ar = arr[i].split("=");
		if(ar[0] == key){
			return ar[1];
		}
	}
}
function sel(data){
    $('select[name="supportworker"]').remove();
    var html = (
        '<select name="supportworker">'
    );
    html += '<option value="'+data.w_id+'">'+data.name+'</option>';
    html += '</select>';
    $('.supportworker_name').append(html);
}
var tId = '';
function addUser(){
    var data = $('.addTrain').serialize();
    $.post('/admin_train/add',data,function(obj){
            if(obj.status == 0){
                    alert(obj.msg);return;
            }
            alert(obj.msg);location.href="/admin_train";
    });
}
</script>
</body>
</html>
